﻿using PARK.Common.Const;
using SqlSugar;
using System;
using Yitter.IdGenerator;

namespace PARK.Attend.Entitys
{
    /// <summary>
    /// 考勤权限管理
    /// </summary>
    [SugarTable("attend_cmdmodel")]
    [Tenant(ClaimConst.TENANT_ID)]
    public class AttendCmdModelEntity
    {
        /// <summary>
        /// 主键Id
        /// </summary>
        [SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
        public string Id { get; set; }        
        /// <summary>
        /// 考勤机Id
        /// </summary>
        [SugarColumn(ColumnName = "machlId")]        
        public string machlId { get; set; }
        /// <summary>
        /// 考勤机SN
        /// </summary>
        [SugarColumn(ColumnName = "DevSN")]        
        public string DevSN { get; set; }
        /// <summary>
        /// 考勤机名称
        /// </summary>
        [SugarColumn(ColumnName = "machName")]
        public string machName { get; set; }
        /// <summary>
        /// 所属区域Id
        /// </summary>
        [SugarColumn(ColumnName = "doorAreaId")]
        public string doorAreaId { get; set; }
        /// <summary>
        /// 所属区域名称
        /// </summary>
        [SugarColumn(ColumnName = "doorAreaName")]
        public string doorAreaName { get; set; }
        /// <summary>
        /// 详细位置
        /// </summary>
        [SugarColumn(ColumnName = "ctlposition")]
        public string ctlposition { get; set; }

        /// <summary>
        /// 执行命令
        /// </summary>
        [SugarColumn(ColumnName = "CmdContent")]
        public string CmdContent { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        [SugarColumn(ColumnName = "CommitTime")]
        public DateTime CommitTime { get; set; }

        /// <summary>
        /// 命令下发时间
        /// </summary>
        [SugarColumn(ColumnName = "TransTime")]
        public DateTime? TransTime { get; set; }
        /// <summary>
        /// 命令回复时间
        /// </summary>
        [SugarColumn(ColumnName = "ResponseTime")]
        public DateTime? ResponseTime { get; set; }
        /// <summary>
        /// 回复结果
        /// </summary>
        [SugarColumn(ColumnName = "ReturnValue")]
        public string ReturnValue { get; set; }
        

        /// <summary>
        /// 权限用户
        /// </summary>
        [SugarColumn(ColumnName = "EmployeeId")]        
        public string EmployeeId { get; set; }
        
        /// <summary>
        /// 工号
        /// </summary>
        [SugarColumn(ColumnName = "JobNo")]        
        public string JobNo { get; set; }
        
        /// <summary>
        /// 姓名
        /// </summary>
        [SugarColumn(ColumnName = "ReallName")]        
        public string ReallName { get; set; }
        /// <summary>
        /// 卡号
        /// </summary>
        [SugarColumn(ColumnName = "CardNo")]
        public string CardNo { get; set; }
        /// <summary>
        /// 部门Id
        /// </summary>
        [SugarColumn(ColumnName = "DepartId")]        
        public string DepartId { get; set; }
        
        /// <summary>
        /// 部门
        /// </summary>
        [SugarColumn(ColumnName = "DepartName")]        
        public string DepartName { get; set; }
       

        /// <summary>
        /// 1 新增， 2 删除
        /// </summary>
        [SugarColumn(ColumnName = "addorDel")]        
        public int? AddorDel { get; set; }
        
        /// <summary>
        /// 创建用户
        /// </summary>
        [SugarColumn(ColumnName = "CreatorUserId")]        
        public string CreatorUserId { get; set; }
        
        /// <summary>
        /// 创建用户姓名
        /// </summary>
        [SugarColumn(ColumnName = "CreatorUserName")]        
        public string CreatorUserName { get; set; }
        
        /// <summary>
        /// 创建时间
        /// </summary>
        [SugarColumn(ColumnName = "CreatorTime")]        
        public DateTime? CreatorTime { get; set; }

        /// <summary>
        /// 命令状态 0待执行 1已提取，执行中 2执行成功 3执行失败
        /// </summary>
        [SugarColumn(ColumnName = "taskStatus")]
        public int taskStatus { get; set; }

        /// <summary>
        /// 所属公司Id
        /// </summary>
        [SugarColumn(ColumnName = "CompanyId")]
        public string CompanyId { get; set; }

        /// <summary>
        /// 公司名称
        /// </summary>
        [SugarColumn(ColumnName = "CompanyName")]
        public string CompanyName { get; set; }
        /// <summary>
        /// 是否彻底删除权限 0否1是
        /// </summary>
        [SugarColumn(ColumnName = "IsDeleteTask")]
        public int IsDeleteTask { get; set; }

        /// <summary>
        /// 创建
        /// </summary>
        public virtual void Create()
        {
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.Id = YitIdHelper.NextId().ToString();
            this.CreatorTime = DateTime.Now;
            this.taskStatus = 0;
            if (!string.IsNullOrEmpty(userId))
            {
                this.CreatorUserId = CreatorUserId == null ? userId : CreatorUserId;
                this.CreatorUserName = CreatorUserName == null ? userName : CreatorUserName;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        public virtual void Delete()
        {
            
        }
    }
}